/**
 * 
 */
package org.ejc.tech.combo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;

import org.apache.log4j.Category;
import org.ejc.api.price.PriceTypeAPIUtil;
import org.ejc.persist.model.PriceType;
import org.ejc.persist.model.RegistrantType;

/**
 * @author Brian Boyle
 *
 */
public class PriceTypeHandlerImpl implements IComboHandler {

	static HashMap map=new HashMap();
	private static final String PREFIX = "org.ejc.type.pricetype.";
	Category log = Category.getInstance(PriceTypeHandlerImpl.class);

	/* (non-Javadoc)
	 * @see org.ejc.tech.combo.IComboHandler#getLocalizedCollection(java.util.Locale)
	 */
	public Collection getLocalizedCollection(Locale locale) {
		return (Collection) map.get(locale.getLanguage());
	}

	/* (non-Javadoc)
	 * @see org.ejc.tech.combo.IComboHandler#setupHandler(java.util.Collection)
	 */
	public void setupHandler(Collection locales) {
		for (Iterator iter = locales.iterator(); iter.hasNext();) {
			Collection<PriceType> priceTypeCol = new ArrayList<PriceType>();
			Locale locale = (Locale) iter.next();
			ResourceBundle resource = ResourceBundle.getBundle(
					"org.ejc.resources.PriceType", locale);
			try {
				Collection c = PriceTypeAPIUtil.getLocalHome().create().getPriceTypes("REGISTRATION");
				for (Iterator iter1 = c.iterator(); iter1.hasNext();) {
					PriceType element = (PriceType) iter1.next();
					String key = PREFIX + element.getPriceTypeDesc();
					String localizedName = (String) resource.getObject(key);


					PriceType priceType = new PriceType();
					priceType.setPriceTypeId(element.getPriceTypeId());
					priceType.setPriceTypeDesc(localizedName);
					priceTypeCol.add(priceType);
				}
			} catch (Exception e) {
				log.fatal("Error in setting up country codes!", e);
			}
			map.put(locale.getLanguage(), priceTypeCol);
		}

	}

}
